﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "IAction.h"
#include "Vector3d.h"
#include "Coordinate3d.h"
#include "TemporaryDimensionDefine.h"
#include "ITemporaryDimensionHandler.h"

namespace gcmp
{
    class IGraphicsNodeGroup;
    class IGraphicsLine;
}

namespace Sample
{
    class TemporaryDimensionCommons
    {
    public:
        /*!
        * @brief     根据视图输入类型和数据, 准备中转计算点集
        * @param[in] inputParam         视图输入参数
        * @param[in] pickedPoints       拾取记录容器
        * @param[in] pickedPoint        最近一次拾取的结果点
        * @param[out] resultPosPts      中转点集
        * @return                       成功与否
        */
        static bool PreparePosForViewInput(
            const gcmp::ActionViewInput& inputParam,
            const std::vector<gcmp::Vector3d>& pickedPoints, const gcmp::Vector3d& newPickedPoint,
            std::vector<gcmp::Vector3d>& resultPosPts);

        /*!
        * @brief     根据视图输入类型和数据, 计算鼠标点位置
        * @param[in] inputParam         视图输入参数
        * @param[in] oPosPts            视图输入数据点集
        * @param[in] coord              所在坐标系
        * @param[out] newPt             鼠标点位置
        * @return                       成功与否
        */
        static bool CalculateNewPosForViewInput(
            const gcmp::ActionViewInput& inputParam, const std::vector<gcmp::Vector3d>& oPosPts,
            const gcmp::Coordinate3d& coord,
            gcmp::Vector3d& newPt, std::wstring& notification);

        /*!
        * @brief     视图输入参数是否是确认输入状态
        * @param[in] inputParam         视图输入参数
        * @return                       是否为确认状态
        */
        static bool IsInputConfirmed(const gcmp::ActionViewInput& inputParam);

        /*!
        * @brief     根据输入数据, 计算矩形角点
        * @param[in] firstDockPt             第一锚点
        * @param[in] secondDockPt            第二锚点
        * @param[in] coord                   工作平面坐标系
        * @param[out] widthStartPt           宽度方向角点
        * @param[out] heightStartPt          高度方向角点
        * @return                            成功与否
        */
        static bool CalcDockPointsForRectangle(
            const gcmp::Vector3d& firstDockPt, const gcmp::Vector3d& secondDockPt,
            const gcmp::Coordinate3d& coord,
            gcmp::Vector3d& widthStartPt, gcmp::Vector3d& heightStartPt);

        /*!
        * @brief     已知弦和半径, 求弧中点
        * @param[in] chordStart              弦起点
        * @param[in] chordEnd                弦终点
        * @param[in] coord                   所在坐标系
        * @param[in] radius                  弧半径
        * @param[in] mousePos                鼠标位置点
        * @param[out] onArcPt                弧中点
        * @return                            成功与否
        */
        static bool GetOnArcPtByChordAndRadius(
            const gcmp::Vector3d& chordStart, const gcmp::Vector3d& chordEnd,
            const gcmp::Coordinate3d coord, double radius, const gcmp::Vector3d& mousePos, gcmp::Vector3d& onArcPt, std::wstring& notification);

        /*!
        * @brief     已知俩切线和半径, 求弧中点
        * @param[in] intersectPt             俩切线交点
        * @param[in] firstTangentLine        其中一条切线方向(要求指向交点)
        * @param[in] secondTangentLine       另一条切线方向(要求指向交点)
        * @param[in] coord                   所在坐标系
        * @param[in] radius                  弧半径
        * @param[out] onArcPt                弧中点
        * @return                            成功与否
        */
        static bool GetOnArcPtByTangentAndRadius(
            const gcmp::Vector3d& intersectPt, const gcmp::Vector3d& firstTangentLine, const gcmp::Vector3d& secondTangentLine,
            const gcmp::Coordinate3d coord, double radius, gcmp::Vector3d& onArcPt, std::wstring& notification);
    };
}

